<template>
<view>
<view class="top-tit">
  <view v-if="orderDetailList.status == 0">等待审核中</view>
  <view v-if="orderDetailList.status == 1">已同意退货，请及时发货</view>
  <view v-if="orderDetailList.status == 2">已拒绝</view>
  <view v-if="orderDetailList.status == 3">金额已还</view>
  <view v-if="orderDetailList.status == 4">买家以发货</view>
  <view v-if="orderDetailList.status == 5">商家收货</view>
  <!-- <view wx:if="{{orderDetailList.status == 6}}">已完成</view> -->
</view>
<view class="consignee" v-if="orderDetailList.status == 1">
  <view class="sjr">收件人信息</view>
    <view class="con-address fl">
      <image src="/static/remao_shop/img/dress_icon.png"></image>
    </view>
    <view class="con-name">
      <text decode="true">{{orderDetailList.return_name}}&ensp;&ensp;&ensp;{{orderDetailList.return_phone}}\n{{orderDetailList.return_address}}</text>
    </view>
  </view>
  <view class="kuaidi" v-if="orderDetailList.status == 1">
    <view class="kd"><text>快递公司:</text><input type="text" @input="gongsiFun" placeholder="请填写快递公司"></input></view>
    <view class="kd bot"><text>快递单号:</text><input type="number" @input="danhaoFun" placeholder="请填写快递单号"></input></view>
  </view>
  <view v-for="(item, index) in orderDetailLista.item" :key="index" class="popup-warp">
    <view class="popup-pic fl">
      <image :src="item.pic"></image>
    </view>
    <view class="pop-warp fr">
      <view class="pop-title">
        <text>{{item.name}}</text>
      </view>
      <view class="pop-spec">
        <text>{{item.pdt_desc}}</text>
      </view>
      <view class="pop-current">
          <view>规格：{{items.pdt_desc}}</view>
      </view>
      <view class="pop-repertory fr">
        <text>x{{item.nums}}</text>
      </view>
    </view>
  </view>
  <view class="details">
    <view class="llei" v-if="orderDetailList.return_type == 1">售后类型：退款</view>
    <view class="llei" v-if="orderDetailList.return_type == 2">售后类型：退货</view>
    <view class="llei">退款金额：<text class="tk_money">{{orderDetailList.amounts}}</text></view>
    <view class="llei">申请原因：{{orderDetailList.describe}}</view>
    <view class="image">
    <view v-for="(item, index) in orderDetailList.imgs" :key="index">
      <image :src="item" mode="aspectFit"></image>
    </view>
  </view>
</view>
<button hover-class="none" @tap="queren" v-if="orderDetailList.status == 1">确认发货</button>


<!-- <view class='order-bot'>
  <view class='orderCopy'>
    <text>订单编号：{{orderDetailList.order_sn}}</text>
    <view class='fuzhi' bindtap='copyOrder'>复制</view>
  </view>
  <view>下单时间：{{orderDetailList.createtime}}</view>
  <view>支付方式：在线支付</view>
</view> -->
</view>
</template>

<script>
import api from "../../../api";
var app = getApp();

export default {
  data() {
    return {
      userId: '',
      orderId: '',
      // 订单详情
      orderDetailList: [],
      orderDetailLista: [],
      // 支付参数
      openId: '',
      // 订单编号
      order_sn: '',
      gongsi: '',
      danhao: ''
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    let openid = wx.getStorageSync("openid");
    let userId = wx.getStorageSync("userId");
    this.setData({
      openId: openid,
      userId: userId,
      order_sn: options.order_sn,
      orderId: options.orderId
    });
    this.getlist();
    this.shoplist();
    console.log(this.orderId);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getlist();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    // 加载数据
    getlist() {
      let that = this;
      app.globalData.request({
        url: api.default.orderrefund_info,
        data: {
          order_id: that.orderId,
          uid: that.userId
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        success: res => {
          console.log(res);
          that.setData({
            orderDetailList: res.refund_info
          });
        },
        fail: function (res) {//失败后的逻辑
        }
      });
    },

    // 加载商品数据
    shoplist() {
      let that = this;
      app.globalData.request({
        url: api.fyz.orderDetail,
        data: {
          order_sn: that.order_sn,
          uid: that.userId
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        success: res => {
          console.log(res);
          that.setData({
            orderDetailLista: res
          });
        },
        fail: function (res) {//失败后的逻辑
        }
      });
    },

    //确认发货
    queren() {
      var that = this;

      if (that.gongsi == '') {
        wx.showToast({
          title: "请输入快递公司",
          icon: 'none'
        });
      } else if (that.danhao == '') {
        wx.showToast({
          title: "请输入快递单号",
          icon: 'none'
        });
      } else {
        app.globalData.request({
          url: api.default.orderrefund_deliver,
          data: {
            order_sn: that.order_sn,
            uid: that.userId,
            express_no: that.danhao,
            express_com: that.gongsi
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded' // 默认值

          },
          method: 'POST',
          success: res => {
            console.log(res);
            wx.showToast({
              title: res.msg,
              icon: 'none'
            });
            setTimeout(function () {
              if (res.status == 1) {
                wx.navigateBack({
                  delta: 1
                });
              }
            }, 1000);
          }
        });
      }
    },

    // 复制订单号
    copyOrder() {
      wx.setClipboardData({
        data: this.orderDetailList.order_sn,

        success(res) {
          console.log(res);
          wx.showToast({
            title: '复制成功',
            icon: 'none'
          });
        }

      });
    },

    gongsiFun(e) {
      console.log(e.detail.value);
      this.setData({
        gongsi: e.detail.value
      });
    },

    danhaoFun(e) {
      console.log(e.detail.value);
      this.setData({
        danhao: e.detail.value
      });
    }

  }
};
</script>
<style>
@import "./aftersale.css";
</style>